package com.campus.web.controller;


import com.alibaba.fastjson.JSON;
import com.campus.app.service.FunctionServer;
import com.campus.app.service.TeachersService;
import com.campus.app.service.impl.FunctionServerImpl;
import com.campus.commons.entity.Class;
import com.campus.commons.entity.Teacher;
import com.campus.commons.entity.User;
import com.campus.commons.utils.Error;
import com.campus.commons.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 老师表 前端控制器
 * </p>
 *
 * @author Rin
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeachersService teachersService;

    @PostMapping("/byRoleId")
    public Result getTeachersByRoleId(Integer roleId) {
        return teachersService.getTeachersByRoleId(roleId);
    }

    @PostMapping("/doesItExistTeacher")
    public Boolean isExis(String name) {
        new FunctionServerImpl().init();
        int integer = 0;
        try {
            integer = FunctionServerImpl.teachers.get(name);
        } catch (Exception e) {
            return false;
        }
        return integer != 0;
    }

    @PostMapping("/all")
    public Result getTeacherAll(int page, int limit) {
        Result<List<Teacher>> teacherAll = teachersService.getTeacherAll(page, limit);
        return teacherAll;
    }

    @PostMapping("/compoundQuery")
    public Result<List<Teacher>> getAllBy(int page, int limit, String teacherName, String phone, String roleName, String idCard) {
        Result<List<Teacher>> listResult = teachersService.getAllBy_xml(page, limit, teacherName, phone, roleName, idCard);
        return listResult;
    }

    @PostMapping("/del")
    public Result del(int id, int userId) {
        Result result = teachersService.delUser(id, userId);
        return result;
    }

    @PostMapping("/update")
    public Result upd(User user, Teacher teacher) {
        Result update = teachersService.update(user, teacher);
        return update;
    }

    @PostMapping("/add")
    public Result add(User user, Teacher teacher) {
        Result addTeacher = teachersService.addTeacher(user, teacher);
        return addTeacher;
    }

    @PostMapping("/checkIdCard")
    public Boolean checkIdCard(String idCard) {
        Boolean aBoolean = teachersService.checkIdCard(idCard);
        return aBoolean;
    }

}



